﻿//=============================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 作 者：孙德响
// 日 期：2011-11-8
// 描 述: 心得编辑界面
//
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00   2011/11/8    孙德响           
//=============================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using ZX.BLL.Extend;
using ZX.DBModule;
using System.Text;
using ZX.Common;
using ZX.TR.Bussiness;
using ZX.TR.Library;
using ZX.EHR.Library;
using ZX.BLL;

namespace ZX.WebApp.TR
{
    /// <summary>
    ///心得编辑界面 
    /// </summary>
    public partial class EditCourseActivity : BasePage
    {
        BTrGainShare Btrac = new BTrGainShare();  //实例化业务处理类
        protected void Page_Load(object sender, EventArgs e)
        {
            ReturnString = this.Review();
        }
        /// <summary>
        /// 实例化与控件赋值
        /// </summary>
        /// <param name="vtrac">实体对象</param>
        public void SetControlEval(V_TrGainShare vtrac)
        {            
            this.txtcoursename.Value = vtrac.CourseName;
            this.txtcoursestartime.Value = vtrac.InfactStartTime.ToString();
            this.txtteachname.Value = vtrac.TeacherName;
            this.txtactivityname.Value = vtrac.ActivityName;
            this.txtusername.Value = vtrac.ShareName;
            this.txtaddtime.Value = vtrac.ShareTime.ToString();
            this.humanid.Value = vtrac.CheckUserid.ToString();
            IList<V_TrGainShareDetail> TrgainshareDetail =Btrac.GetShareDetail("TrGainShareID='" + vtrac.TrGainShareID + "' And   ShareType='0' order by Exp1 asc");
            if (TrgainshareDetail != null)
            {
                for (int i =0;i< TrgainshareDetail.Count;i++)
                {
                    #region  ========10点心得赋值============
                    if (i == 0)
                    {
                        this.course1.Value = TrgainshareDetail[0].ShareContent;
                    }
                    if (i == 1)
                    {
                        this.course2.Value = TrgainshareDetail[1].ShareContent;
                    }
                    if (i == 2)
                    {
                        this.course3.Value = TrgainshareDetail[2].ShareContent;
                    }
                    if (i == 3)
                    {
                        this.course4.Value = TrgainshareDetail[3].ShareContent;
                    }
                    if (i == 4)
                    {
                        this.course5.Value = TrgainshareDetail[4].ShareContent;
                    }
                    if (i == 5)
                    {
                        this.course6.Value = TrgainshareDetail[5].ShareContent;
                    }
                    if (i == 6)
                    {
                        this.course7.Value = TrgainshareDetail[6].ShareContent;
                    }
                    if (i == 7)
                    {
                        this.course8.Value = TrgainshareDetail[7].ShareContent;
                    }
                    if (i == 8)
                    {
                        this.course9.Value = TrgainshareDetail[8].ShareContent;
                    }
                    if (i == 9)
                    {
                        this.course10.Value = TrgainshareDetail[9].ShareContent;
                    }
                    #endregion                   
                }
            }
            IList<V_TrGainShareDetail> TrgainshareDetail5 = Btrac.GetShareDetail("TrGainShareID='" + vtrac.TrGainShareID + "' And   ShareType='5'");
            if (TrgainshareDetail5 != null)
            {
                for (int i = 0; i < TrgainshareDetail5.Count; i++)
                {
                    #region  ========5点心得赋值============
                    if (i == 0)
                    {
                        this.CoursePrepare1.Value = TrgainshareDetail5[0].ShareContent;
                    }
                    if (i == 1)
                    {
                        this.CoursePrepare2.Value = TrgainshareDetail5[1].ShareContent;
                    }
                    if (i == 2)
                    {
                        this.CoursePrepare3.Value = TrgainshareDetail5[2].ShareContent;
                    }
                    if (i == 3)
                    {
                        this.CoursePrepare4.Value = TrgainshareDetail5[3].ShareContent;
                    }
                    if (i == 4)
                    {
                        this.CoursePrepare5.Value = TrgainshareDetail5[4].ShareContent;
                    }                 
                    #endregion
                }
            }
            IList<V_TrGainShareDetail> TrgainshareDetail3 = Btrac.GetShareDetail("TrGainShareID='" + vtrac.TrGainShareID + "' And   ShareType='3'");
            if (TrgainshareDetail3 != null)
            {
                for (int i = 0; i < TrgainshareDetail3.Count; i++)
                {
                    #region  ========3点心得赋值============
                    if (i == 0)
                    {
                        this.CoursePrepare6.Value = TrgainshareDetail3[0].ShareContent;
                    }
                    if (i == 1)
                    {
                        this.CoursePrepare7.Value = TrgainshareDetail3[1].ShareContent;
                    }
                    if (i == 2)
                    {
                        this.CoursePrepare8.Value = TrgainshareDetail3[2].ShareContent;
                    }                   
                    #endregion
                }
            }
            IList<V_TrGainShareDetail> TrgainshareDetail1 = Btrac.GetShareDetail("TrGainShareID='" + vtrac.TrGainShareID + "' And   ShareType='1'");
            if (TrgainshareDetail1 != null)
            {
                for (int i = 0; i < TrgainshareDetail1.Count; i++)
                {
                    #region  ========1点心得赋值============
                    if (i == 0)
                    {
                        this.CoursePrepare9.Value = TrgainshareDetail1[0].ShareContent;
                    }                   
                    #endregion
                }
            }   
               
           
        }
        public string ReturnString
        {
            get;
            set;
        }
        /// <summary>
        /// 生成处理界面
        /// </summary>
        /// <returns></returns>
        public string Review()
        {
            string strEntity = this.GetStringFromQueryString("entity", "V_TrActivityCourseX");   //实体类
            string id = this.GetStringFromQueryString("ID", "");        //课程活动的主键          
            DatUser du = (DatUser)System.Web.HttpContext.Current.Session["User"]; //用户ID
            string table1 = string.Empty;
            string table2 = string.Empty;
            if (du != null)
            {
                int type = int.Parse(this.GetStringFromQueryString("type", "1"));    //备注 1：做新增心得  2：做编辑心得   3:新增/编辑点评  4:查看
                if (type == 1)
                {
                    #region ==========新增心得============
                    this.txtusername.Value = du.UName;
                    this.txtaddtime.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                    return "";
                    #endregion
                }
                else if (type == 2)
                {
                    #region   ==========编辑心得============
                    this.Btrac.entity = new V_TrGainShare();
                    V_TrGainShare VGainShare = (V_TrGainShare)Btrac.GetEntityById(id);
                    if (VGainShare != null)
                    {
                        //BUser buser = new BUser();
                        //如果当前用户不是客户经理(负责人)则可以编辑点评，否则不可编辑点评
                        if ((VGainShare.CheckUserid.ToString().Trim().Length != 0)
                            && (VGainShare.CheckUserid.ToString() != "00000000-0000-0000-0000-000000000000")
                            && (VGainShare.CheckUserid == du.UserID))
                        {
                            EnableControl(4);
                            table1 = "<table   style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 600px; line-height:20px;\" ><tr><td class=\"style91\">点评人</td><td class=\"style22\">"
                                    + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + VGainShare.CheckName + "' /></td><td class=\"style92\">点评时间</td><td  class=\"style97\">&nbsp;"
                                    + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + VGainShare.CheckTime.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>";
                            table2 = "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2;    background-color:#F2F8FF; white-space: nowrap; width: 600px;\" ><tr><td class=\"style74\">点评内容</td><td class=\"style94\">";
                            table2 += "<textarea id=\"Review1\"  runat=\"server\" name=\"TrMessageIssueID0\" class=\"yui-area\" disabled=\"disabled\" style=\"overflow:hidden\">" + VGainShare.CheckContent + "</textarea></td></tr> </table>";
                        }
                        else if ((VGainShare.ShareUserid.ToString().Trim().Length != 0)
                            && (VGainShare.ShareUserid.ToString() != "00000000-0000-0000-0000-000000000000")
                            && (VGainShare.ShareUserid == du.UserID) && (VGainShare.CheckContent.ToString().Trim().Length == 0))  //还没有点评   心得人可以修改
                        {
                            EnableControl(2);
                            table1 = "<table   style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 600px; line-height:20px;\" ><tr><td class=\"style91\">点评人</td><td class=\"style22\">"
                                   + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + VGainShare.CheckName + "' /></td><td class=\"style92\">点评时间</td><td  class=\"style97\">&nbsp;"
                                   + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + VGainShare.CheckTime.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>";

                            table2 = "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2;    background-color:#F2F8FF; white-space: nowrap; width: 600px;\" ><tr><td class=\"style74\">点评内容</td><td class=\"style94\">";
                            table2 += "<textarea id=\"Review1\"  runat=\"server\" name=\"TrMessageIssueID0\" class=\"yui-area\" disabled=\"disabled\" style=\"overflow:hidden\">" + VGainShare.CheckContent + "</textarea></td></tr> </table>";
                        }
                        else //不可编辑点评
                        {
                            EnableControl(4);
                            table1 = "<table   style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 600px; line-height:20px;\" ><tr><td class=\"style91\">点评人</td><td class=\"style22\">"
                                   + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + VGainShare.CheckName + "' /></td><td class=\"style92\">点评时间</td><td  class=\"style97\">&nbsp;"
                                   + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + VGainShare.CheckTime.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>";

                            table2 = "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2;    background-color:#F2F8FF; white-space: nowrap; width: 600px;\" ><tr><td class=\"style74\">点评内容</td><td class=\"style94\">";
                            table2 += "<textarea id=\"Review1\"  runat=\"server\" name=\"TrMessageIssueID0\" class=\"yui-area\" disabled=\"disabled\" style=\"overflow:hidden\">" + VGainShare.CheckContent + "</textarea></td></tr> </table>";
                        }

                        SetControlEval(VGainShare);
                    }
                    #endregion
                }
                else if (type == 3)
                {
                    #region   =========新增/编辑点评=========
                    this.Btrac.entity = new V_TrGainShare();
                    V_TrGainShare VGainShare = (V_TrGainShare)Btrac.GetEntityById(id);
                    if (VGainShare != null)
                    {
                        //BUser buser = new BUser();
                        //DatUser duser = new DatUser();
                        EnableControl(4);
                        if ((VGainShare.CheckUserid.ToString().Trim().Length != 0) && 
                            (VGainShare.CheckUserid.ToString() != "00000000-0000-0000-0000-000000000000") &&
                            (VGainShare.CheckUserid == du.UserID))
                        {
                            //duser = buser.GetDatUserByUserId(VGainShare.ShareUserid);
                            table1 = "<table   style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 600px; line-height:20px;\" ><tr><td class=\"style91\">点评人</td><td class=\"style22\">"
                            + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + VGainShare.CheckName + "' /></td><td class=\"style92\">点评时间</td><td  class=\"style97\">&nbsp;"
                            + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + VGainShare.CheckTime.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>";

                            table2 = "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 600px;\" ><tr><td class=\"style74\">点评内容</td><td class=\"style94\">";
                            table2 += "<textarea id=\"Review1\"  runat=\"server\" name=\"TrMessageIssueID0\" class=\"yui-area\" style=\"overflow:hidden\" >" + VGainShare.CheckContent + "</textarea></td></tr> </table>";
                        }
                        else
                        {
                            //duser = buser.GetDatUserByUserId(VGainShare.CheckUserid);
                            table1 = "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 600px; line-height:20px;\"  ><tr><td class=\"style91\">点评人</td><td class=\"style22\">"
                                + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\" class=\"style80\" disabled=\"disabled\" value='" + VGainShare.CheckName + "' /></td><td class=\"style92\">点评时间</td><td class=\"style97\">&nbsp;"
                                + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\" class=\"style80\" disabled=\"disabled\" value='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>";

                            table2 = "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 600px;\"><tr><td class=\"style74\">点评内容</td><td class=\"style94\">";
                            table2 += "<textarea id=\"Review1\"  runat=\"server\" name=\"TrMessageIssueID0\" class=\"yui-area\" disabled=\"disabled\" style=\"overflow:hidden\"></textarea></td></tr> </table>";
                        }
                        SetControlEval(VGainShare);
                    }
                    #endregion
                }
                else if (type == 4)
                {
                    #region ==============查看=============
                    this.Btrac.entity = new V_TrGainShare();
                    V_TrGainShare VGainShare = (V_TrGainShare)Btrac.GetEntityById(id);
                    if (VGainShare != null)
                    {
                        //BUser buser = new BUser();                     
                        EnableControl(4);
                        if ((VGainShare.CheckUserid.ToString().Trim().Length != 0) &&
                            (VGainShare.CheckUserid.ToString() != "00000000-0000-0000-0000-000000000000") &&
                            (VGainShare.CheckUserid == du.UserID))
                        {
                            table1 = "<table   style=\"font-weight:normal;  border: solid 1px #D4DBE2;    background-color:#F2F8FF;    white-space: nowrap; width: 600px; line-height:20px;\" ><tr><td class=\"style91\">点评人</td><td class=\"style22\">"
                            + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\"  class=\"style80\"  disabled=\"disabled\" value='" + VGainShare.CheckName + "' /></td><td class=\"style92\">点评时间</td><td  class=\"style97\">&nbsp;"
                            + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\"  class=\"style80\"  disabled=\"disabled\" value='" + VGainShare.CheckTime.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>";

                            table2 = "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2;    background-color:#F2F8FF;    white-space: nowrap; width: 600px;\" ><tr><td class=\"style74\">点评内容</td><td class=\"style94\">";
                            table2 += "<textarea id=\"Review1\"  runat=\"server\" name=\"TrMessageIssueID0\" class=\"yui-area\"  style=\"overflow:hidden\" disabled=\"disabled\">" + VGainShare.CheckContent + "</textarea></td></tr> </table>";
                        }
                        else
                        {
                            table1 = "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2;    background-color:#F2F8FF;    white-space: nowrap; width: 600px; line-height:20px;\"  ><tr><td class=\"style91\">点评人</td><td class=\"style22\">"
                                + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\"  class=\"style80\"  disabled=\"disabled\" value='" + VGainShare.CheckName + "' /></td><td class=\"style92\">点评时间</td><td class=\"style97\">&nbsp;"
                                + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\"  class=\"style80\"  disabled=\"disabled\" value='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>";
                            table2 = "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2;    background-color:#F2F8FF;    white-space: nowrap; width: 600px;\"><tr><td class=\"style74\">点评内容</td><td class=\"style94\">";
                            table2 += "<textarea id=\"Review1\"  runat=\"server\" name=\"TrMessageIssueID0\" class=\"yui-area\" style=\"overflow:hidden\" disabled=\"disabled\"></textarea></td></tr> </table>";
                        }
                        SetControlEval(VGainShare);
                    }
                    #endregion
                }
            }
            return table1+table2;
        }
        /// <summary>
        /// 控件设置
        /// </summary>
        private void EnableControl(int type)
        {
            if (type == 2)  //编辑心得。
            {
                this.txtusername.Disabled = true;
                this.txtaddtime.Disabled = true;
                this.txtactivityname.Disabled = true;
                this.txtcoursename.Disabled = true;
                this.txtteachname.Disabled = true;
                this.txtcoursestartime.Disabled = true;
                this.btnSelect.Visible = false;
            }
            else if (type == 4)  //设置控件不可编辑
            {
                this.txtusername.Disabled = true;
                this.txtaddtime.Disabled = true;
                this.txtactivityname.Disabled = true;
                this.txtcoursename.Disabled = true;
                this.txtteachname.Disabled = true;
                this.txtcoursestartime.Disabled = true;
                this.btnSelect.Visible = false; 
                this.course1.Disabled = true;
                this.course2.Disabled = true;
                this.course3.Disabled = true;
                this.course4.Disabled = true;
                this.course5.Disabled = true;
                this.course6.Disabled = true;
                this.course7.Disabled = true;
                this.course8.Disabled = true;
                this.course9.Disabled = true;
                this.course10.Disabled = true;
                this.CoursePrepare1.Disabled = true;
                this.CoursePrepare2.Disabled = true;
                this.CoursePrepare3.Disabled = true;
                this.CoursePrepare4.Disabled = true;
                this.CoursePrepare5.Disabled = true;
                this.CoursePrepare6.Disabled = true;
                this.CoursePrepare7.Disabled = true;
                this.CoursePrepare8.Disabled = true;
                this.CoursePrepare9.Disabled = true;
            }
        }
    }
}